package jmine.tec.rpc.integration.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;
import bancosys.tec.persist.persister.annotation.NaturalKey;

/**
 * @author lundberg
 */
@Entity
@Table(name = "MOCK_ENTITY")
@Alias("MOCKE")
@SequenceGenerator(name = "SEQ_MOCK", sequenceName = "SEQ_MOCK")
@Documentation("TABELA DE TESTES.")
public class MockEntity extends PersistableBusinessObject {

    private Long id;

    private String value;

    private List<AssociatedMockEntity> references = new ArrayList<AssociatedMockEntity>();

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_MOCK")
    @Column(name = "ID")
    @Documentation("TABELA DE TESTES.")
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the value
     */
    @NaturalKey
    @Column(name = "VALUE")
    @Documentation("TABELA DE TESTES.")
    public String getValue() {
        return this.value;
    }

    /**
     * @param value the value to set
     */
    public void setValue(String value) {
        this.value = value;
    }

    /**
     * @return the references
     */
    @OneToMany(mappedBy = "mock")
    @Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    @Documentation("TABELA DE TESTES.")
    public List<AssociatedMockEntity> getReferences() {
        return this.references;
    }

    /**
     * @param references the references to set
     */
    public void setReferences(List<AssociatedMockEntity> references) {
        this.references = references;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return new HashCodeBuilder().append(this.id).append(this.value).append(this.references).toHashCode();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof MockEntity)) {
            return false;
        }
        MockEntity o = (MockEntity) obj;
        return new EqualsBuilder().append(this.id, o.id).append(this.value, o.value).append(this.references, o.references).isEquals();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}